package com.ts.service.user.Impl;

import com.ts.dto.UserLoginDTO;
import com.ts.entity.User;
import com.ts.mapper.user.UserMapper;
import com.ts.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    /**
     * 用户登录
     * @param userLoginDTO
     * @return
     */
    @Override
    public User login(UserLoginDTO userLoginDTO) {
        String username = userLoginDTO.getUserName();
        String password = userLoginDTO.getUserPwd();

        //1.根据用户名查询数据库中的数据
        User user = userMapper.getUserByUserName(username);

        //2.处理异常情况：账号不存在


        password = DigestUtils.md5DigestAsHex(password.getBytes());

        //3.处理异常情况：密码错误

        //返回实体对象
        return user;
    }
}
